const MATH_NS = 'http://www.w3.org/1998/Math/MathML';
const HTML_NS = 'http://www.w3.org/1999/xhtml';
const SVG_NS = 'http://www.w3.org/2000/svg';

export let ns = HTML_NS;

export function useNS(namespace: string) {
	return function (proc: () => Node) {
		const previousNs = ns;
		ns = namespace;
		try {
			return proc();
		} finally {
			ns = previousNs;
		}
	};
}

export const NS = {
	HTML: HTML_NS as typeof HTML_NS,
	SVG: SVG_NS as typeof SVG_NS,
	MATH: MATH_NS as typeof MATH_NS,
	html: useNS(HTML_NS),
	svg: useNS(SVG_NS),
	math: useNS(MATH_NS),
};
